package cn.lcsjsxy.yxz.day.Set;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

//迭代器
public class iterator1 {

    public static void main(String[] args) throws Exception{

        //
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        map.put("a",1);
        map.put("b",2);
        map.put("c",3);

        Set<String> keys = map.keySet();

        for (String key : keys){
            if ("c".equals(key)){
                map.remove("b");
            }
            System.out.println(map.get(key));
        }

        //迭代器
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()){
            //判断是否存在下一条数据
            String key = iterator.next();
            if ("b".equals(key)){
                //remove方法只能对当前数据删除
                iterator.remove();
            }
            System.out.println(map.get(key));
        }




    }

}
